<?php /*a:5:{s:56:"D:\phpstudy_pro\WWW\tp\app\admin\view\article\index.html";i:1656075034;s:49:"D:\phpstudy_pro\WWW\tp\app\admin\view\layout.html";i:1640261441;s:54:"D:\phpstudy_pro\WWW\tp\app\admin\view\common\meta.html";i:1655800829;s:56:"D:\phpstudy_pro\WWW\tp\app\admin\view\common\header.html";i:1640261441;s:56:"D:\phpstudy_pro\WWW\tp\app\admin\view\common\footer.html";i:1640261441;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<script src="/static/layui/layui.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="/static/layui/js-3.1.1.min.js"></script>
    <title>VeeCMF 通用后台管理系统 - 快速接口开发 快速后台开发</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black">VeeCMF</div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
        <!-- 移动端显示 -->
        <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
            <i class="layui-icon layui-icon-spread-left"></i>
        </li>
        <?php foreach($layout_menu_list as $key=>$vo): if($vo['position'] == '1'): if($vo['show'] == '1'): if($vo['status'] == '1'): if(is_array($promise_menu_id) == true): foreach($promise_menu_id as $idx=>$menu_id): if($menu_id == $vo['id']): ?>
                        <li class="layui-nav-item layui-hide-xs"><a href="<?php echo htmlentities($vo['route']); ?>"><?php echo htmlentities($vo['title']); ?></a></li>
                    <?php endif; ?>
                <?php endforeach; else: ?>
                    <li class="layui-nav-item layui-hide-xs"><a href="<?php echo htmlentities($vo['route']); ?>"><?php echo htmlentities($vo['title']); ?></a></li>
                <?php endif; ?>
            <?php endif; ?>
            <?php endif; ?>
            <?php endif; ?>
        <?php endforeach; ?>
<!--        <li class="layui-nav-item">-->
<!--            <a href="javascript:;">工具</a>-->
<!--            <dl class="layui-nav-child">-->
<!--                <dd><a href="">尚未开发</a></dd>-->
<!--            </dl>-->
<!--        </li>-->
    </ul>
    <ul class="layui-nav layui-layout-right">
        <li class="layui-nav-item layui-hide layui-show-md-inline-block">
            <a href="javascript:;">
                <img src="<?php echo htmlentities($rootData['avatar_src']); ?>" class="layui-nav-img">
                <?php echo htmlentities($rootData['root_name']); ?>
            </a>
            <dl class="layui-nav-child">
<!--                <dd><a href="">个人资料</a></dd>-->
<!--                <dd><a href="">个人设置</a></dd>-->
                <dd><a href="/admin/login/logout">退出登录</a></dd>
            </dl>
        </li>
        <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
            <a href="javascript:;">
                <i class="layui-icon layui-icon-more-vertical"></i>
            </a>
        </li>
    </ul>
</div>


<div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
        <ul class="layui-nav layui-nav-tree" lay-filter="test" id="menu">

        </ul>
    </div>
</div>
<script>
    var res = <?php echo $layout_menu_list_json; ?>

    $("#menu").html('')
    layui.use('element', function () {
        element = layui.element;
        //console.log(res)
        let header = '';
        res.forEach( v => {
            header += `
                            <li class="layui-nav-item" id="header_${v.id}"><a href="javascript:;">${v.title}</a></li>
                        `
            var content = '<li class="layui-nav-item">';
            if(v.position == 0 && v.status == 1 && v.show == 1){
                content += '<a href="javascript:;">' + v.title + '</a>';
                content += loadchild(v);
                content += '</li>';
            }
            //这里是添加所有的子菜单
            $("#menu").append(content);
        })
        $('#layuiHeader').html(header)

        element.init();

        // 表头点击事件
        $("#layuiHeader").on("click", 'li', function() {
            // 表头添加样式
            $.each($(this).siblings(), function (i, e) {
                $(e).find("a").removeClass('layui-this')
            });
            $(this).find("a").addClass('layui-this');

            // 侧边栏
            let id = $(this).attr("id").split('_')[1];
            //console.log(id)
            let newArr = res.filter( v => {
                return v.id == id
            })
            // console.log(newArr[0])

            $("#menu").html('');

            newArr.forEach( v => {
                var content = '<li class="layui-nav-item">';
                if(v.position == 0 && v.status == 1 && v.show == 1) {
                    content += '<a href="javascript:;">' + v.title + '</a>';
                    //这里是添加所有的子菜单
                    content += loadchild(v);
                    content += '</li>';
                }
                $("#menu").append(content);
            })
            element.init();

        })
    });


    //组装子菜单的方法
    function loadchild(obj) {
        if (obj == null) {
            return;
        }
        var content = '';
        if (obj.child != null && obj.child.length > 0) {
            content += '<dl class="layui-nav-child">';
        } else {
            content += '<dl>';
        }

        if (obj.child != null && obj.child.length > 0) {
            $.each(obj.child, function (i, note) {
                if(note.position == 0 && note.status == 1 && note.show == 1) {
                    content += '<dd>';
                    content += '<a href="' + note.route + '" onclick="viewClick(' + note.parent_id + ')">' + note.title + '</a>';
                    if (note.child == null) {
                        return;
                    }
                    content += loadchild(note);
                    content += '</dd>';
                }
            });

            content += '</dl>';
        }
        //console.log(content);
        return content;
    }

    // 侧边栏点击事件
    function viewClick(parent_res_id) {
        //console.log(parent_res_id);
        $('#header_' + parent_res_id)
        $.each($('#header' + parent_res_id).siblings(), function (i, e) {
            $(e).find("a").removeClass('layui-this')
        });
        $('#header_' + parent_res_id).find("a").addClass('layui-this');
    }
</script>

    <div class="layui-body">
        <div class="layui-bg-gray" style="padding: 5px;">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-panel">
                        <div style="padding: 0.5rem 1rem;">
                            <span class="layui-breadcrumb" lay-separator="—">
                            <?php foreach($menuAllParent as $key=>$vo): if($vo['isChild'] == '1'): ?>
                                    <a><cite><?php echo htmlentities($vo['title']); ?></cite></a>
                                <?php else: ?>
                                    <a href="<?php echo htmlentities($vo['route']); ?>"><?php echo htmlentities($vo['title']); ?></a>
                                <?php endif; ?>
                            <?php endforeach; ?>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-bg-gray" style="padding: 5px;">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-panel">
                        <div style="padding: 0.5rem 1rem;">
                            <div style="padding: 15px;">
<form class="layui-form">
    <div class="layui-input-inline">
        <input type="text" name="searchData" autocomplete="off" placeholder="搜索关键字" class="layui-input">
    </div>
    <div class="layui-inline">
        <div class="layui-input-inline" style="width: 70px">
            <select name="searchField" lay-verify="required">
                <option value="title">标题</option>
                <option value="content">内容</option>
                <option value="author_id">作者ID</option>
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <div class="layui-input-inline" style="width: 100px">
            <select name="searchWhere" lay-verify="required">
                <option value="like">模糊查询</option>
                <option value="=">精准查询</option>
            </select>
        </div>
    </div>
    <div class="layui-input-inline " style="width: 70px">
        <div class="layui-btn" id="searchBtn" data-type="reload">
            <i class="layui-icon" style="font-size: 14px; "></i> 搜索
        </div>
    </div>
</form>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addUser">添加</button>
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="getCheckData">删除选中行</button>
        <!--        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
        <!--        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    </div>
</script>

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="显示|未审核" lay-filter="status" {{
           d.status == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="barDemo">
<!--        <a class="layui-btn layui-btn-xs" lay-event="edit">权限管理</a>-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use(['table','util'], function(){
        var table = layui.table;
        var util = layui.util;
        var form = layui.form;

        table.render({
            elem: '#test'
            ,url:'/admin/article/getArticleListJson'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '菜单列表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, unresize: true, sort: true}
                ,{field:'title', title:'文章标题',edit:'text',width:120, sort: true}
                // ,{field:'author_id', title:'作者ID', edit:'text',width:100, sort: true,}
                ,{field:'author_type', title:'用户名',width:100, sort: true,templet: function(res){
                        if(res.admin_root){
                            return res.admin_root.root_name;
                        }else{
                            return "错误作者ID";
                        }
                    }}
                ,{field:'author_type', title:'作者类型',width:100, sort: true,templet: function(res){
                    if(res.admin_root_group){
                        return res.admin_root_group.root_group_name;
                    }else{
                        return "错误类型ID";
                    }
                    }}
                ,{field:'content', title:'文章内容', edit:'text',width:100, sort: true,}
                ,{field:'category_id', title:'分类ID', edit:'text',width:100, sort: true,}
                ,{field:'status', title:'状态', width:120,templet: '#statusTpl', unresize: true}
                ,{field:'create_time', title:'创建时间', width:180}
                ,{field:'update_time', title:'修改时间', width:180} //每次登录时更新该时间
                ,{fixed:'right', title:'操作', toolbar: '#barDemo', width:100}
            ]]
            ,page: true
            ,limit: 20 //默认每页显示条数
        });



        //监听状态操作，修改状态
        form.on('switch(status)', function(obj){
            console.log('id:'+this.value,'key:'+this.name,'value:'+obj.elem.checked, obj.othis);
            //调用修改权重接口
            var value = obj.elem.checked ? 1:0;
            var editData = [
                {
                    'id':this.value,
                    [this.name]:value
                }
            ];
            $.ajax({
                url: "/admin/article/editList",
                type: "POST",
                data:{
                    'editArray':editData,
                },
                dataType: "json",
                success: function(result){
                    console.log(result)
                    if(result.code === 0){
                        layer.msg(result.msg);
                    }
                },
                error:function(err){
                    console.log(err.statusText);
                }
            });
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    var idArray=[];
                    data.filter(item =>{
                        idArray.push(item.id);
                    })
                    layer.confirm('真的删除行么', function(index){
                        //layer.alert(JSON.stringify(data));
                        console.log('idArray:',idArray);
                        layer.close(index);
                        //调用删除接口
                        $.ajax({
                            url: "/admin/article/del",
                            type: "POST",
                            data:{
                                'idArray':idArray
                            },
                            dataType: "json",
                            success: function(result){
                                console.log(result)
                                if(result.code === 0){
                                    layer.msg(result.msg);
                                    location.reload();
                                }
                            },
                            error:function(err){
                                console.log(err.statusText);
                            }
                        });
                    });
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
                case 'addUser':
                    window.open('/admin/article/add');
                    break;
                // case 'search':
                //     var searchData = form.val('searchForm');
                //     table.reload('test',{
                //         elem: '#test'
                //         ,url:'/admin/article/searchArticleListJson'
                //         ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                //         ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                //             title: '提示'
                //             ,layEvent: 'LAYTABLE_TIPS'
                //             ,icon: 'layui-icon-tips'
                //         }]
                //         ,title: '菜单列表'
                //         ,cols: [[
                //             {type: 'checkbox', fixed: 'left'}
                //             ,{field:'id', title:'ID', width:80, unresize: true, sort: true}
                //             ,{field:'title', title:'文章标题',edit:'text',width:120, sort: true}
                //             ,{field:'author_id', title:'作者ID', edit:'text',width:100, sort: true,}
                //             ,{field:'author_type', title:'作者类型', edit:'text',width:100, sort: true,}
                //             ,{field:'content', title:'文章内容', edit:'text',width:100, sort: true,}
                //             ,{field:'category_id', title:'分类ID', edit:'text',width:100, sort: true,}
                //             ,{field:'status', title:'状态', width:120,templet: '#statusTpl', unresize: true}
                //             ,{field:'create_time', title:'创建时间', width:180}
                //             ,{field:'update_time', title:'修改时间', width:180} //每次登录时更新该时间
                //             ,{fixed:'right', title:'操作', toolbar: '#barDemo', width:100}
                //         ]]
                //         ,page: true
                //         ,limit: 20 //默认每页显示条数
                //     });
                //     break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听单元格编辑
        table.on('edit(test)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            if(field === 'sort'){
                if (!(/(^[1-9]\d*$)/.test(util.escape(value)))) {
                    layer.msg('输入值无效，请输入非零开头的正整数');
                    return false;
                }
            }
            if(util.escape(value) > 9999){
                layer.msg('输入值应该小于等于9999');
                return false;
            }
            console.log('[ID: '+ data.id +'] ' + field + ' 字段更改值为：'+ util.escape(value));
            var editData = [
                {
                    'id':data.id,
                    [field]:util.escape(value),
                }
            ];
            console.log(editData);
            //调用修改权重接口
            $.ajax({
                url: "/admin/article/editList",
                type: "POST",
                data:{
                    'editArray':editData,
                },
                dataType: "json",
                success: function(result){
                    console.log(result)
                    if(result.code === 0){
                        layer.msg(result.msg);
                    }
                },
                error:function(err){
                    console.log(err.statusText);
                }
            });
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                var idArray=[];
                idArray.push(data.id);
                layer.confirm('真的删除行么', function(index){
                    console.log("删除:"+idArray);
                    obj.del();
                    layer.close(index);
                    //调用删除接口
                    $.ajax({
                        url: "/admin/article/del",
                        type: "POST",
                        data:{
                            'idArray':idArray
                        },
                        dataType: "json",
                        success: function(result){
                            console.log(result)
                            if(result.code === 0){
                                layer.msg(result.msg);
                                location.reload();
                            }
                        },
                        error:function(err){
                            console.log(err.statusText);
                        }
                    });
                });
            } else if(obj.event === 'edit'){
                window.open('/admin/article/auth/id/'+data.id);
            }
        });

        //搜索加载--数据表格重载
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('test', {
                    url:'/admin/article/searchArticleListJson',
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        searchField: $("select[name=searchField]").val(),
                        searchWhere: $("select[name=searchWhere]").val(),
                        searchData: $("input[name=searchData]").val()
                    }
                });
            }
        };
        $('#searchBtn').on('click', function () {
            ids=new Array();
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        element.init();
    });
</script>
</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--<div class="layui-footer">-->
<!--    &lt;!&ndash; 底部固定区域 &ndash;&gt;-->
<!--    底部固定区域-->
<!--</div>-->

<script>
    //JS
    layui.use(['element', 'layer', 'util'], function(){
        var element = layui.element
            ,layer = layui.layer
            ,util = layui.util
            ,$ = layui.$;

        //头部事件
        util.event('lay-header-event', {
            //左侧菜单事件
            menuLeft: function(othis){
                layer.msg('展开左侧菜单的操作', {icon: 0});
            }
            ,menuRight: function(){

                layer.open({
                    type: 1
                    ,content: '<div id="msgList"></div>'
                    ,area: ['260px', '100%']
                    ,offset: 'rt' //右上角
                    ,anim: 5
                    ,shadeClose: true
                });
                var html = '';
                $.ajax({
                    url: "http://1.117.149.125:81/api/msgList",
                    type: "GET",
                    data:{
                        'data':'',
                    },
                    dataType: "json",
                    success: function(data){
                        data['data'].forEach(function(item) {
                            console.log(item);
                            html += '<div style="padding: 15px;">'+item['content']+'</div>';
                        });
                        $('#msgList').html(html);
                    },
                    error:function(err){
                        console.log(err.statusText);
                    }
                });
            }
        });

    });
</script>
</div>

</body>
</html>